package com.hxzy.shop.controller.commodity;

import com.github.pagehelper.PageInfo;
import com.hxzy.shop.dto.commodity.req.PageRequst;
import com.hxzy.shop.dto.commodity.req.RechargeReq;
import com.hxzy.shop.dto.commodity.resp.RechargeResp;
import com.hxzy.shop.entity.MerchantPlugs;
import com.hxzy.shop.entity.MerchantPlugspaylog;
import com.hxzy.shop.entity.SysPlugs;
import com.hxzy.shop.feign.commodity.CommodityFeign;
import com.hxzy.shop.vo.ApiException;
import com.hxzy.shop.vo.Result;
import com.hxzy.shop.vo.ResultCode;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author qy
 * @Description:
 * @date:2021/8/10 17:17
 */

@RestController
@Api(tags = "处方单购买")
@RequestMapping("/buyPre")
public class PrescriptionBuyController {

    @Resource
    private CommodityFeign commodityFeign;

    @ApiOperation("处方单/短信使用详情")
    @PostMapping("/preUseInfo")
    public Result<MerchantPlugs> getPreInfo(@RequestBody PageRequst pageRequst) {
        Result<MerchantPlugs> preInfo = commodityFeign.getPreInfo(pageRequst);
        if (preInfo.getCode() != ResultCode.SUCCESS.getCode()) {
            throw new ApiException(500, preInfo.getMsg());
        }
        return Result.success(preInfo.getData());
    }

    @ApiOperation("充值")
    @PostMapping("/recharge")
    public Result<RechargeResp> recharge(@ApiParam(readOnly = true, name = "rechargeReq", value = "充值参数对象")
                                         @RequestBody RechargeReq rechargeReq) throws Exception {
        Result<RechargeResp> recharge = commodityFeign.recharge(rechargeReq);
        if (recharge.getCode() != ResultCode.SUCCESS.getCode()) {
            throw new ApiException(500, recharge.getMsg());
        }
        return Result.success(recharge.getData());
    }

    @ApiOperation("加载插件信息")
    @PostMapping("/loadPlugInfo")
    public Result<SysPlugs> loadPlugInfo(@RequestBody PageRequst pageRequst){
        Result<SysPlugs> sysPlugsResult =commodityFeign.loadPlugInfo(pageRequst);

        if (sysPlugsResult.getCode() != ResultCode.SUCCESS.getCode()) {
            throw new ApiException(500, sysPlugsResult.getMsg());
        }
        return Result.success(sysPlugsResult.getData());
    }

    @ApiOperation("获取商户充值列表")
    @PostMapping("/getRechargePage")
    public Result<PageInfo<MerchantPlugspaylog>> getRechargePage(@ApiParam(required = true, name = "pageRequst", value = "处方单购买记录分页参数对象")
                                                                 @RequestBody PageRequst pageRequst){
        Result<PageInfo<MerchantPlugspaylog>> rechargePage = commodityFeign.getRechargePage(pageRequst);
        if (rechargePage.getCode() != ResultCode.SUCCESS.getCode()) {
            throw new ApiException(500, rechargePage.getMsg());
        }
        return Result.success(rechargePage.getData());
    }

}
